<?php
class Task {
    
    const ANSWER_TYPE_TEXT = 0;
    const ANSWER_TYPE_FILE = 1;
    
    private $model;

    private $context;
    
    public function __construct($task_data = array(), $context) {
        $this->context = $context;
        if(!empty($task_data))
        {
            foreach ($task_data as $key => $value) {
                $this->{$key} = $value;
            }
        }
    }
    
    public function getAnswerType() {
        
        switch ($this->answer_type) {
            case self::ANSWER_TYPE_TEXT:
                $ret = new TextAnswerType($this->context);
                break;
            case self::ANSWER_TYPE_FILE:
                $ret = new FileAnswerType($this->context);
                break;
            default:
                break;
        }
        return $ret;
    }
    
    public static function load($task_id, $context)
    {
        Registry::getInstance()->load->library('class.TaskModel.php', 'performer');
        $model = new TaskModel();
        if(!$model->hasTaskInBase($task_id)) throw new Exception('task not found');
        $task_data = $model->getTask($task_id);
        
        return new Task($task_data, $context);
    }
    
    
    
}
?>
